﻿using System.Collections.ObjectModel;
using Inovout.Gui.Wpf.ViewModels;
using Inovout.Portal.Desktop.Controls;
using System.Linq;

namespace Inovout.Portal.Desktop.Workbenchs
{
    public class RibbonWorkbenchViewModel : MainWorkbenchViewModel
    {
        private ObservableCollection<RibbonTabViewModel> tabs;
        public ObservableCollection<RibbonTabViewModel> Tabs
        {
            get
            {
                if (tabs == null)
                {
                    tabs = new ObservableCollection<RibbonTabViewModel>(RibbonDescriptor.Build(this));
                }
                return tabs;
            }
        }

        protected override void Workspace_CurrentChanged(object sender, System.EventArgs e)
        {
            base.Workspace_CurrentChanged(sender, e);
            RibbonTabViewModel tab = tabs.FirstOrDefault(t =>
                t.Functions.FirstOrDefault(f =>
                    f.DependentFunction != null
                    &&f.DependentFunction.Equals(
                        ((DomainViewModel)ActivedWorkspace).ViewContext.Function)) != null);
            tab.IsSelected = true;
        }
    }
}
